package com.qmds.deviceserver.product.service.impl;

import com.qmds.common.minio.utils.MinioUtils;
import com.qmds.deviceserver.product.service.UploadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author ShiJiaWei
 * @date 2024/8/22
 * @desc:
 */
@Service
public class UploadServiceImpl implements UploadService {

    @Resource
    private MinioUtils minioUtils;

    @Override
    public String upload(MultipartFile file) {

        // 获取原始文件名
        String fileName = file.getOriginalFilename();

        String uuid = UUID.randomUUID().toString().replace("-", "");

        // 修改文件名，按照指定的规则修改，本例增加了一个时间戳
        String[] split = fileName.split("\\.");
        if (split.length > 1) {
            fileName = uuid + "." + split[1];
        } else {
            fileName = uuid;
        }

        return minioUtils.upload(file, fileName);
    }
}
